﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SpaceNeedle.City6473.Web.Data.Helpers
{
    public static class Text
    {
        public static string AbbreviateName(string name)
        {
            if(string.IsNullOrEmpty(name))
            {
                return name;
            }

            string[] parts = name.Split(' ', '_', '-', '.', ',', ';', ':', '|');

            string abbreviatedName = string.Empty;

            if(parts.Length == 0)
            {
                return name.ToUpper();
            }
            else if(parts.Length == 1)
            {
                if(parts[0].Length == 0)
                {
                    return name.ToUpper();
                }

                abbreviatedName = (parts[0][0] + ".").ToUpper();
            }
            else if(parts.Length == 2)
            {
                abbreviatedName = (parts[0][0] + ". ").ToUpper() + System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(parts[1]);
            }
            else
            {
                for (int i = 0; i < parts.Length - 1; i++)
                {
                    abbreviatedName += (parts[i][0] + ". ").ToUpper();
                }

                abbreviatedName +=  System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(parts[parts.Length - 1]);
            }

            return abbreviatedName;
        }
    }
}
